package com.bishe.demo.modules.hotel.hotelFacilityAndService.dao;

import com.bishe.demo.modules.hotel.hotelFacilityAndService.entity.Facility;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface FacilityDao {
    @Insert("insert into hotel_facility values(null,#{facilityName})")
    @Options(useGeneratedKeys = true, keyProperty = "facilityId", keyColumn = "facility_id")
    void insertFacility(Facility facility);

    @Select("select * from hotel_facility hf left join  hotel_facility_user hfu on hfu.facility_id=hf.facility_id where hfu.user_id=#{hotelId}")
    @Results(id = "facilityResult", value = {
            @Result(property = "facilityId", column = "facility_id"),
            @Result(property = "facilityImages", column = "facility_id",
                    javaType = List.class,
                    many = @Many(select = "com.bishe.demo.modules.hotel.common.dao.HotelImageDao.getImagesByFacilityId"))
    })
    List<Facility> getFacilitiesByHotelId(int hotelId);

    @Delete("delete from hotel_facility where facility_id=#{facilityId}")
    void deleteById(int facilityId);
}
